package mq.demo.simple;

import cn.itlaobing.Util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author mifei
 * @create 2018年04月12日
 **/
public class Send {
    private final static String QUEUE_NAME = "mq_test_simple";

    public static void main(String[] argv) throws Exception {
        // 获取连接
        Connection connection = ConnectionUtil.getConnection();
        // 创建通道
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("abc", "direct");


        // 声明队列 (不存在则创建)
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        for (int i = 0; i <50 ; i++) {
            // 发送消息
            String message = "Hello World"+i;
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
        }

        // 关闭通道和连接
        channel.close();
        connection.close();
    }
}
